package com.fzh.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fzh.mapper.ProductTypeMapper;
import com.fzh.pojo.entity.ProductType;
import com.fzh.pojo.utils.ResponeMessageUtil;
import com.fzh.service.ProductTypeService;

@Service
public class ProductTypeServiceImpl implements ProductTypeService {
	
	@Autowired
	private ProductTypeMapper productTypeMapper;

	@Override
	public List<ProductType> queryAllProductType(Integer setValue, Integer limit, String name, String p_id) {
		return productTypeMapper.selectAllProductType(setValue,limit,name,p_id);
	}

	@Override
	public int queryProductTypeCounts(String name,String p_id) {
		return productTypeMapper.selectProductTypeCounts(name,p_id);
	}

	@Override
	public List<ProductType> queryTwoEvlProductType() {
		return productTypeMapper.selectTwoEvlProductType();
	}

	@Override
	public Boolean addProductType(ProductType productType) {
		return ResponeMessageUtil.getResMsg(productTypeMapper.insertProductType(productType));
	}

	@Override
	public Boolean editProductTypeById(ProductType productType) {
		return ResponeMessageUtil.getResMsg(productTypeMapper.updateProductTypeById(productType));
	}

	@Override
	public Boolean delAllProductTypeByIds(String id) {
		
		String[] split = id.split(",");
		List<String> ids = new ArrayList<>();
		for(int i = 0; i < split.length; i ++) {
			ids.add(split[i]);
		}
		
		return ResponeMessageUtil.getResMsg(productTypeMapper.deleteAllProductTypeByIds(ids));
	}

	@Override
	public Boolean delProductTypeById(Integer id) {
		return ResponeMessageUtil.getResMsg(productTypeMapper.deleteProductTypeById(id));
	}

	@Override
	public List<ProductType> queryProductTypeName() {
		return productTypeMapper.selectProductTypeName();
	}

	@Override
	public Boolean queryAllProductTypeNameWitchVerify(String typeName) {
		List<ProductType> productType = productTypeMapper.selectAllProductTypeNameWitchVerify(typeName);
		if(productType != null && productType.size() > 0) {
			return true;
		}else {
			return false;
		}
		
	}

	@Override
	public List<ProductType> queryAllProduct() {
		return productTypeMapper.selectAllProductTypeF();
	}
	
	@Override
	public Boolean queryProductTypeBelowIsSonProductTypeByP_id(Integer id) {
		List<ProductType> productTypes = productTypeMapper.selectProductTypeBelowIsSonProductTypeByP_id(id);
		//查询商品类型表，返回集合来判断内容是否有值，来进行返回
		if(productTypes.size() > 0) {
			return true;
		}else {
			return false;
		}
	}
	

	@Override
	public List<ProductType> selectAllProductTypeByPid() {
		return productTypeMapper.selectAllProductTypeByPid();
	}
	
	public List<ProductType> selectAllProductTypeByP_id(Integer p_id) {
		return productTypeMapper.selectAllProductTypeByP_id(p_id);
	}
	

}
